<template>
  <div class="content">
    <div class="head">
      <h2>热门精选</h2>
      <div class="house">
        <div
          class="houselist"
          v-for="item in houseList"
          :key="item.data.houseId">
          <!-- discoveryContentType === 9 -->
          <div class="house-type9" v-if="item.discoveryContentType === 9">
            <div class="type-img">
              <img :src="item.data.image.url" alt="" />
            </div>
            <div class="type-text">
              <div class="information">{{ item.data.summaryText }}</div>
              <div class="description">{{ item.data.houseName }}</div>
              <div class="box">
                <div class="rate">
                  <van-rate
                    :model-value="Number(item.data.commentScore)"
                    size="13"
                    void-icon="star"
                    void-color="#fff"
                    color="#ffd21e"
                    readonly
                    allow-half />
                </div>
                <div class="house-price">￥{{ item.data.finalPrice }}</div>
              </div>
            </div>
          </div>
          <!-- discoveryContentType === 3 -->
          <div class="house-type3" v-else-if="item.discoveryContentType === 3">
            <div class="type-img">
              <img :src="item.data.image.url" alt="" />
            </div>
            <div class="city-position">
              <van-icon name="location" />
              {{ item.data.location }}
            </div>
            <div class="description">{{ item.data.houseName }}</div>
            <div class="information">{{ item.data.summaryText }}</div>
            <div class="house-price">
              <span>￥{{ item.data.finalPrice }}</span>
              <span
                v-if="item.data.productPrice || item.data.productPrice === 0">
                ￥{{ item.data.productPrice }}
              </span>
              <span v-if="item.data.priceTipBadge.text">
                <b>{{ item.data.priceTipBadge.text }}</b>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import useHomeStore from '@/stores/modeules/home'
import { storeToRefs } from 'pinia'

const homeStore = useHomeStore()
const { houseList } = storeToRefs(homeStore)
</script>

<style scoped lang="scss">
.head {
  h2 {
    margin-left: 10px;
  }
}
.house {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  .houselist {
    margin: 5px auto;
    width: 185px;
    height: 200px;
    position: relative;
    .house-type9 {
      // type === 9
      .type-img {
        overflow: hidden;
        width: 100%;
        position: absolute;
        z-index: -999;
        display: flex;
        justify-content: center;
        align-items: center;
        img {
          min-width: 100%;
          max-height: 200px;
        }
      }
      .type-text {
        color: white;
        font-size: 13px;
        position: absolute;
        bottom: 0;
        left: 0;
        padding: 10px;
        .description {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          text-overflow: ellipsis;
          margin: 5px auto;
        }
        .box {
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
      }
    }
    .house-type3 {
      // type === 3
      .type-img {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        img {
          min-width: 100%;
          max-height: 100px;
        }
      }
      .city-position {
        display: flex;
        align-items: center;
        margin: 5px auto;
      }
      .description {
        font-size: 13px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        margin: 5px auto;
      }
      .information {
        margin: 5px auto;
      }
      .house-price {
        span:nth-child(1) {
          color: #f0c29e;
        }
        span:nth-child(2) {
          color: #a8a6ab;
          text-decoration: line-through;
        }
        span:nth-child(3) {
          background: #f66064;
          border-radius: 18px;
          b {
            color: white;
            font-size: 12px;
            padding: 5px 10px;
          }
        }
      }
    }
  }
}
</style>
